package org.loong.crypto.extension.cms;

import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.X509CRL;
import java.security.cert.X509Certificate;

import org.loong.crypto.core.Parameters;

/**
 * The data crypto parameters.
 */
public class CMSParameters implements Parameters {

    /**
     * 操作.
     */
    private String way;

    /**
     * 数据类型.
     */
    private String dataFormat;

    /**
     * 待处理数据.
     */
    private byte[] data;

    /**
     * 加密方法.
     */
    private String encryptionMethod;

    /**
     * 接收者证书.
     */
    private X509Certificate encryptionCertificate;

    /**
     * 接收者公钥.
     */
    private PublicKey encryptionPublicKey;

    /**
     * 签名方法.
     */
    private String signatureAlgorithm;

    /**
     * 签名证书.
     */
    private X509Certificate signingCertificate;

    /**
     * 签名者公钥.
     */
    private PublicKey signingPublicKey;

    /**
     * 签名者/接收者私钥.
     */
    private PrivateKey privateKey;

    /**
     * 不签名属性.
     */
    private boolean hasNoSignedAttributes;

    private X509CRL[] crls;

    /**
     * no args constructor.
     */
    public CMSParameters() {}

    /**
     * builder constructor.
     *
     * @param builder builder
     */
    private CMSParameters(final Builder builder) {
        this.way = builder.way;
        this.dataFormat = builder.dataFormat;
        this.data = builder.data;
        this.encryptionMethod = builder.encryptionMethod;
        this.encryptionCertificate = builder.encryptionCertificate;
        this.encryptionPublicKey = builder.encryptionPublicKey;
        this.signatureAlgorithm = builder.signatureAlgorithm;
        this.signingCertificate = builder.signingCertificate;
        this.privateKey = builder.privateKey;
        this.signingPublicKey = builder.signingPublicKey;
        this.hasNoSignedAttributes = builder.hasNoSignedAttributes;
        this.crls = builder.crls;
    }

    /**
     * class builder.
     *
     * @return builder
     */
    public static Builder builder() {
        return new Builder();
    }

    /**
     * Gets the value of way.
     *
     * @return the value of way
     */
    public String getWay() {
        return way;
    }

    /**
     * Sets the way.
     *
     * @param way the way to set
     */
    public void setWay(final String way) {
        this.way = way;
    }

    /**
     * Gets the value of dataFormat.
     *
     * @return the value of dataFormat
     */
    public String getDataFormat() {
        return dataFormat;
    }

    /**
     * Sets the dataFormat.
     *
     * @param dataFormat the dataFormat to set
     */
    public void setDataFormat(final String dataFormat) {
        this.dataFormat = dataFormat;
    }

    /**
     * Gets the value of data.
     *
     * @return the value of data
     */
    public byte[] getData() {
        return data;
    }

    /**
     * Sets the data.
     *
     * @param data the data to set
     */
    public void setData(final byte[] data) {
        this.data = data;
    }

    /**
     * Gets the value of encryptionMethod.
     *
     * @return the value of encryptionMethod
     */
    public String getEncryptionMethod() {
        return encryptionMethod;
    }

    /**
     * Sets the encryptionMethod.
     *
     * @param encryptionMethod the encryptionMethod to set
     */
    public void setEncryptionMethod(final String encryptionMethod) {
        this.encryptionMethod = encryptionMethod;
    }

    /**
     * Gets the value of encryptionCertificate.
     *
     * @return the value of encryptionCertificate
     */
    public X509Certificate getEncryptionCertificate() {
        return encryptionCertificate;
    }

    /**
     * Sets the encryptionCertificate.
     *
     * @param encryptionCertificate the encryptionCertificate to set
     */
    public void setEncryptionCertificate(final X509Certificate encryptionCertificate) {
        this.encryptionCertificate = encryptionCertificate;
    }

    /**
     * Gets the value of encryptionPublicKey.
     *
     * @return the value of encryptionPublicKey
     */
    public final PublicKey getEncryptionPublicKey() {
        return encryptionPublicKey;
    }

    /**
     * Sets the encryptionPublicKey.
     *
     * @param encryptionPublicKey the encryptionPublicKey to set
     */
    public final void setEncryptionPublicKey(final PublicKey encryptionPublicKey) {
        this.encryptionPublicKey = encryptionPublicKey;
    }

    /**
     * Gets the value of signatureAlgorithm.
     *
     * @return the value of signatureAlgorithm
     */
    public String getSignatureAlgorithm() {
        return signatureAlgorithm;
    }

    /**
     * Sets the signatureAlgorithm.
     *
     * @param signatureAlgorithm the signatureAlgorithm to set
     */
    public void setSignatureAlgorithm(final String signatureAlgorithm) {
        this.signatureAlgorithm = signatureAlgorithm;
    }

    /**
     * Gets the value of signingCertificate.
     *
     * @return the value of signingCertificate
     */
    public X509Certificate getSigningCertificate() {
        return signingCertificate;
    }

    /**
     * Sets the signingCertificate.
     *
     * @param signingCertificate the signingCertificate to set
     */
    public void setSigningCertificate(final X509Certificate signingCertificate) {
        this.signingCertificate = signingCertificate;
    }

    /**
     * Gets the value of signingPublicKey.
     *
     * @return the value of signingPublicKey
     */
    public final PublicKey getSigningPublicKey() {
        return signingPublicKey;
    }

    /**
     * Sets the signingPublicKey.
     *
     * @param signingPublicKey the signingPublicKey to set
     */
    public final void setSigningPublicKey(final PublicKey signingPublicKey) {
        this.signingPublicKey = signingPublicKey;
    }

    /**
     * Gets the value of privateKey.
     *
     * @return the value of privateKey
     */
    public PrivateKey getPrivateKey() {
        return privateKey;
    }

    /**
     * Sets the privateKey.
     *
     * @param privateKey the privateKey to set
     */
    public void setPrivateKey(final PrivateKey privateKey) {
        this.privateKey = privateKey;
    }

    /**
     * Gets the value of hasNoSignedAttributes.
     *
     * @return the value of hasNoSignedAttributes
     */
    public boolean isHasNoSignedAttributes() {
        return hasNoSignedAttributes;
    }

    /**
     * Sets the hasNoSignedAttributes.
     *
     * @param hasNoSignedAttributes the hasNoSignedAttributes to set
     */
    public void setHasNoSignedAttributes(final boolean hasNoSignedAttributes) {
        this.hasNoSignedAttributes = hasNoSignedAttributes;
    }

    /**
     * Gets the value of crls.
     *
     * @return the value of crls
     */
    public X509CRL[] getCrls() {
        return crls;
    }

    /**
     * Sets the crls.
     *
     * @param crls the crls to set
     */
    public void setCrls(final X509CRL[] crls) {
        this.crls = crls;
    }

    /**
     * class builder.
     */
    public static final class Builder {

        private String way;

        private String dataFormat;

        private byte[] data;

        private String encryptionMethod;

        private X509Certificate encryptionCertificate;

        private PublicKey encryptionPublicKey;

        private String signatureAlgorithm;

        private X509Certificate signingCertificate;

        private PublicKey signingPublicKey;

        private PrivateKey privateKey;

        private boolean hasNoSignedAttributes = false;

        private X509CRL[] crls;

        /**
         * no args constructor.
         */
        private Builder() {}

        /**
         * build new Object.
         *
         * @return this
         */
        public CMSParameters build() {
            return new CMSParameters(this);
        }

        /**
         * build way.
         *
         * @param way the way
         * @return this
         */
        public Builder way(final String way) {
            this.way = way;
            return this;
        }

        /**
         * build dataFormat.
         *
         * @param dataFormat the dataFormat
         * @return this
         */
        public Builder dataFormat(final String dataFormat) {
            this.dataFormat = dataFormat;
            return this;
        }

        /**
         * build data.
         *
         * @param data the data
         * @return this
         */
        public Builder data(final byte[] data) {
            this.data = data;
            return this;
        }

        /**
         * build encryptionMethod.
         *
         * @param encryptionMethod the encryptionMethod
         * @return this
         */
        public Builder encryptionMethod(final String encryptionMethod) {
            this.encryptionMethod = encryptionMethod;
            return this;
        }

        /**
         * build encryptionCertificate.
         *
         * @param encryptionCertificate the encryptionCertificate
         * @return this
         */
        public Builder encryptionCertificate(final X509Certificate encryptionCertificate) {
            this.encryptionCertificate = encryptionCertificate;
            return this;
        }

        /**
         * build encryptionPublicKey.
         *
         * @param encryptionPublicKey the encryptionPublicKey
         * @return this
         */
        public Builder encryptionPublicKey(final PublicKey encryptionPublicKey) {
            this.encryptionPublicKey = encryptionPublicKey;
            return this;
        }

        /**
         * build signatureAlgorithm.
         *
         * @param signatureAlgorithm the signatureAlgorithm
         * @return this
         */
        public Builder signatureAlgorithm(final String signatureAlgorithm) {
            this.signatureAlgorithm = signatureAlgorithm;
            return this;
        }

        /**
         * build signingCertificate.
         *
         * @param signingCertificate the signingCertificate
         * @return this
         */
        public Builder signingCertificate(final X509Certificate signingCertificate) {
            this.signingCertificate = signingCertificate;
            return this;
        }

        /**
         * build signingPublicKey.
         *
         * @param signingPublicKey the signingPublicKey
         * @return this
         */
        public Builder signingPublicKey(final PublicKey signingPublicKey) {
            this.signingPublicKey = signingPublicKey;
            return this;
        }

        /**
         * build privateKey.
         *
         * @param privateKey the privateKey
         * @return this
         */
        public Builder privateKey(final PrivateKey privateKey) {
            this.privateKey = privateKey;
            return this;
        }

        /**
         * build hasNoSignedAttributes.
         *
         * @param hasNoSignedAttributes the hasNoSignedAttributes
         * @return this
         */
        public Builder hasNoSignedAttributes(final boolean hasNoSignedAttributes) {
            this.hasNoSignedAttributes = hasNoSignedAttributes;
            return this;
        }

        /**
         * build crls.
         *
         * @param crls the crls
         * @return this
         */
        public Builder crls(final X509CRL[] crls) {
            this.crls = crls;
            return this;
        }
    }
}
